<template>
  <page-layout>
    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div>
        <a-form @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :md="8" :sm="8">
              <a-form-item label="订单编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input style="display: none" v-model="queryParam.orderNo"></a-input>
                <a-input style="width:100%;" placeholder="请输入订单编码" v-model="queryParam.orderNo"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="8">
              <a-form-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input style="width:100%;" placeholder="请输入姓名" v-model="queryParam.wxName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="8">
              <a-form-item label="电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input style="width:100%;" placeholder="请输入电话" v-model="queryParam.wxPhone"></a-input>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row :gutter="24">
            <a-col :md="8" :sm="8">
              <a-form-item label="业务类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <z-dict-select-tag  v-model="queryParam.bizType" placeholder="请选择业务类型" dictCode="bizType"/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="8">
              <a-form-item label="订单状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <z-dict-select-tag  v-model="queryParam.status" placeholder="请选择订单状态" dictCode="status"/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="8">
              <a-form-item style="float: right">
                <a-button type="primary" @click="searchQuery()" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset()" icon="reload" style="margin-left: 8px">重置</a-button>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <!-- table区域-begin -->
      <div>
        <vxe-grid
            id="OrderList"
            keep-source
            ref="vxeTable"
            :height="null"
            v-bind="options"
            @page-change="handlePageChange"
        >
          <template #action="{ row }">
            <template>
              <a @click="handleDetail(row)">详情</a>
              <a-divider type="vertical" />
              <a-dropdown>
                <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                <a-menu slot="overlay">
                  <a-menu-item v-if="row.status !=='50'">
                    <a @click="distribute(row)"><span v-if="row.designerId">重新</span>分配</a>
                  </a-menu-item>
                  <a-menu-item>
                    <a-popconfirm title="将清除已分配的群组，确定吗?" @confirm="() => handleDelete(row.id)">
                      <a>删除</a>
                    </a-popconfirm>
                  </a-menu-item>
                </a-menu>
              </a-dropdown>
            </template>
          </template>
        </vxe-grid>
      </div>
      <!-- table区域-end -->
      <GroupListModal @ok="modalFormOk" ref="modalGroupForm" />
      <OrderDetailModal @ok="modalFormOk" ref="modalForm" />
    </a-card>
  </page-layout>
</template>

<script>
import PageLayout from '@/layouts/PageLayout'
import { VxeTableMixin } from '@/mixins/VxeTableMixin'
import ZDictSelectTag from '@/components/dict/ZDictSelectTag'
import GroupListModal from './modules/GroupListModal'
import OrderDetailModal from './modules/OrderDetailModal'
import Criteria from '@/utils/criteria'
import { OPERATOR } from '@/store/mutation-types'
import { filterObj } from '@/utils/util'
export default {
  name: 'OrderList',
  components: {
    OrderDetailModal,
    PageLayout,
    ZDictSelectTag,
    GroupListModal
  },
  mixins: [VxeTableMixin],
  data() {
    return {
      columns: [
        {
          title: '订单编码',
          field: 'orderNo',
          width: 150,
          showOverflow: true
        },
        {
          title: '创建时间',
          field: 'createTime',
          width: 200,
          showOverflow: true
        },
        {
          title: '姓名',
          field: 'wxName',
          width: 100,
          showOverflow: true
        },
        {
          title: '电话',
          field: 'wxPhone',
          width: 150,
          showOverflow: true
        },
        {
          title: '业务类型',
          field: 'bizType',
          width: 150,
          showOverflow: true,
          formatter: 'dictText',
          sorter: true
        },
        {
          title: '期望交付日期',
          field: 'expectDate',
          width: 150,
          showOverflow: true
        },
        {
          title: '订单状态',
          field: 'status',
          showOverflow: true,
          width: 150,
          formatter: 'dictText'
        },
        {
          title: '设计师',
          field: 'designerName',
          width: 150,
          showOverflow: true
        },
        {
          title: '校对',
          field: 'checkName',
          width: 150,
          showOverflow: true
        },
        {
          title: '后工',
          field: 'afterWorkName',
          width: 150,
          showOverflow: true
        },
        {
          title: '操作',
          slots: { default: 'action' },
          width: 250,
          fixed: 'right'
        }
      ],
      exportFileName: '订单信息报表.xlsx',
      elementId: 'order:order-list:export',
      auth: { 'permi': { 'add': '' }},
      url: {
        list: '/doc/order/v1/page',
        delete: 'doc/order/v1/remove/',
        exportXlsUrl: '/doc/order/v1/exportPage'
      },
      // 查询参数
      queryParam: {
        status: '10' // 未接单
      },
      customTableToolbar: {
        buttons: [],
        export: false,
        import: false
      }
    }
  },
  computed: {
    rowSelection() {
      return {
        selectedRowKeys: this.selectedRowKeys,
        onChange: this.onSelectChange
      }
    }
  },
  methods: {
    searchReset() {
      this.queryParam = { status: '10' }
      this.loadData(1)
    },
    distribute(row) {
      this.$refs.modalGroupForm.edit(row)
    },
    getQueryParams() {
      // 获取查询条件
      const queryParam = new Criteria()
      queryParam.addCriterions(Object.assign({}, this.queryParam, this.filters), OPERATOR.LIKE)// 过滤参数转换为jpa支持格式
      if (this.superQueryParams) {
        queryParam.concatCriterions(this.superQueryParams)
      }
      this.isorter && queryParam.addOrder(this.isorter)// 增加排序规则
      const param = Object.assign({}, { criteria: queryParam.getEncode() })
      param.pageNo = this.ipagination.currentPage
      param.pageSize = this.ipagination.pageSize
      return filterObj(param)
    }
  }
}
</script>
